package com.yeming.flink.practice.tablesql

import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.table.api.{DataTypes, EnvironmentSettings, Table, Types}
import org.apache.flink.table.api.scala.StreamTableEnvironment
import org.apache.flink.table.sources.CsvTableSource

object TestCreateTableByFile {

  def main(args: Array[String]): Unit = {
    //使用flink原生代码创建TableEnvironment
    //先初始化上下文环境
    val streamEnv: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
    val settings: EnvironmentSettings = EnvironmentSettings.newInstance().useOldPlanner().inStreamingMode().build()
    val tableEnv: StreamTableEnvironment = StreamTableEnvironment.create(streamEnv, settings)

    val source = new CsvTableSource("/station.log"
      , Array[String]("f1", "f2", "f3", "f4", "f5", "f6")
      , Array(Types.STRING(), Types.STRING(), Types.STRING(), Types.STRING(), Types.LONG(), Types.LONG()))

    tableEnv.registerTableSource("t_station_info",source)
    val table: Table = tableEnv.scan("t_station_info")
    table.printSchema()



  }

}
